package com.grablist.feihu.grablist.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;

import java.io.InputStream;

/**
 * Created by JINAN on 2017/10/16.
 */

public class ImgUtils {

    public static void imageLoader(ImageView imageView, String url, Drawable error) {
        Glide.with(imageView.getContext()).load(url).error(error).into(imageView);
    }

    public static void imageLoader(ImageView imageView, String url) {
        Glide.with(imageView.getContext()).load(url).into(imageView);
}

//    public static void imageTransform(Context context, ImageView imageView, String url) {
//
//        Glide.with(context).load(url).transform(new GlideRoundTransform(context)).into(imageView);
//
//    }

    public static Bitmap readBitMap(Context context, int resId) {
        BitmapFactory.Options opt = new BitmapFactory.Options();
        opt.inPreferredConfig = Bitmap.Config.RGB_565;
        opt.inPurgeable = true;
        opt.inInputShareable = true;

        InputStream is = context.getResources().openRawResource(resId);
        return BitmapFactory.decodeStream(is, null, opt);
    }
}
